package com.rsk.api;


import java.util.Map;

import javax.ws.rs.QueryParam;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.rsk.api.common.ReturnUtils;
import com.rsk.service.SysUserService;
import com.rsk.utils.json.JsonUtils;
import com.rsk.utils.result.Result;
import com.rsk.utils.result.ResultBuilder;
import com.rsk.utils.result.ResultCode;

@RestController
@RequestMapping(value="/sys/user")
public class SystemUserApi {
	
	@Reference(interfaceClass = SysUserService.class, protocol = "dubbo")
	private SysUserService sysUserService;
	
	
	//@RequiresPermissions("sys_users:save")
	@PostMapping(value="/saveSysUser" )
	public Result<String> saveSysUser(@QueryParam("account") String account,
			   						  @QueryParam("passWord") String passWord,
			   						  @QueryParam("userName") String userName,
			   						  @QueryParam("status") Integer status,
			   						  @QueryParam("levelId") Long levelId,
			   						  @QueryParam("rolelId") Long rolelId,
			   						  @RequestHeader("Authorization") String Authorization){
		//数据校验
		//String operatorUser = JwtUtil.getClaim(Authorization, "account");
		Long operatorUser = 123L;
		int i = sysUserService.saveSysUser(account, passWord, userName, status, levelId, rolelId, operatorUser);
		return ReturnUtils.returnDataByOne(i);
	}
	
	//@RequiresPermissions("sys_users:update")
	@PostMapping(value="/updateSysUsers" )
	public Result<String> updateSysUsers(@QueryParam("account") String account,
									   @QueryParam("passWord") String passWord,
								   	   @QueryParam("userName") String userName,
								   	   @QueryParam("status") Integer status){
		//数据校验
				//String operatorUser = JwtUtil.getClaim(Authorization, "account");
				Long operatorUser = 123L;
		int i = sysUserService.updateSysUser(account, passWord,userName,status,operatorUser);
		return ResultBuilder.success(JsonUtils.objectToJson(i), ResultCode.SUCCESS);
	}
	
	
	
	//@RequiresPermissions("sys_users:del")
	@PostMapping(value="/delSysUser" )
	public Result<String> delSysUser(@QueryParam("id") Long id,
									 @QueryParam("account") String account,
									 @RequestHeader("Authorization") String Authorization){
		//数据校验
		//String operatorUser = JwtUtil.getClaim(Authorization, "account");
		Long operatorUser = 123L;
		int i = sysUserService.delSysUser(id, account, operatorUser);
		return ReturnUtils.returnDataByOne(i);
	}
	
	
	//@RequiresPermissions("sys_users:del")
	@PostMapping(value="/updateSysUserStatus" )
	public Result<String> updateSysUserStatus(@QueryParam("id") Long id,
									          @QueryParam("account") String account,
									          @QueryParam("status") Integer status,
									          @RequestHeader("Authorization") String Authorization){
		//数据校验
		//String operatorUser = JwtUtil.getClaim(Authorization, "account");
		Long operatorUser = 123L;
		int i = sysUserService.updateSysUserStatus(id, account, status, operatorUser);
		return ReturnUtils.returnDataByOne(i);
	}


}
